package com.allqj.sfx.ddd.member.application.assembler;

import com.allqj.sfx.application.assembler.DTOAssembler;
import com.allqj.sfx.ddd.member.application.dto.FlowDefDTO;
import com.allqj.sfx.ddd.member.domain.entity.flow.FlowDef;
import org.springframework.beans.BeanUtils;

import java.util.stream.Collectors;

/**
 * @author sjw
 * @className FlowDefAssember
 * @date 2022/7/22 18:47
 * @description: FlowDefDTO&FlowDef 转换类
 * DTO与entity之间的转换
 */
public class FlowDefAssember implements DTOAssembler<FlowDefDTO, FlowDef> {

    public static FlowDefAssember INSTANCE = new FlowDefAssember();

    @Override
    public FlowDef dto2Entity(FlowDefDTO flowDefDTO) {
        if (flowDefDTO == null)
            return null;
        FlowDef flowDef = new FlowDef();
        BeanUtils.copyProperties(flowDefDTO, flowDef, "flowTaskDefs");
        flowDef.setFlowTaskDefs(flowDefDTO.getFlowTaskDefs().stream().map(flowTaskDefDTO -> FlowTaskDefAssember.INSTANCE.dto2Entity(flowTaskDefDTO)).collect(Collectors.toList()));
        return flowDef;
    }

    @Override
    public FlowDefDTO entity2DTO(FlowDef flowDef) {
        return null;
    }
}
